
package com.example.paper.common.datam.migrate.reader;

import com.example.paper.common.datam.constant.KeyConstant;
import com.example.paper.common.datam.migrate.job.JobCache;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 描述.
 *
 * @author Long Fengfan, 2022年10月17日

 */

@Component
public abstract class BaseReader<T> implements Reader<T> {

    @Override
    public List<T> read(Map<String, Object> readerParams, Map<String, Object> processorParams, CommonBlock commonBlock) {
        String jobId = processorParams.get(KeyConstant.job_id).toString();
        Integer processId = (Integer) processorParams.get(KeyConstant.process_id);
        boolean isError = JobCache.isErrorCache.get(jobId).get(processId);
        if (!isError) {
            return doRead(readerParams, commonBlock);
        } else {
            return Collections.emptyList();
        }

    }

    public abstract List<T> doRead(Map<String, Object> processParams, CommonBlock commonBlock);

    // 移植
    @Override
    public int getBatchSize() {
        return 10;
    }


}
